//
//  ViewController.m
//  CZQStudyDemo
//
//  Created by 陈志强 on 2019/11/28.
//  Copyright © 2019 陈志强. All rights reserved.
//

#import "ViewController.h"
#import "CZQMansoryController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, copy) NSInteger (^testBlock)(NSInteger num);
@property (nonatomic, strong) NSArray *dataSource;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellStudy"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellStudy"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = [self.dataSource objectAtIndex:indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *item = [self.dataSource objectAtIndex:indexPath.row];
    if ([item isEqualToString:@"Masonry"]) {
        CZQMansoryController *ctr = [[CZQMansoryController alloc] init];
        [self.navigationController pushViewController:ctr animated:YES];
    }else if ([item isEqualToString:@"SDWebImage"]){
        self.testBlock = ^NSInteger(NSInteger num) {
            return num*3;
        };
        NSInteger sum = self.testBlock(5);
        NSLog(@"sum =%ld",sum);
    }
}

#pragma mark --Lazy Method
- (NSArray *)dataSource{
    if (_dataSource==nil) {
        _dataSource = @[@"AFNetworking",@"Masonry",@"SDWebImage"];
    }
    return _dataSource;
}

@end
